package com.mayikt;

import java.util.concurrent.CountDownLatch;

/**
 * @Author: maplefire
 * @Description: CountDownLatchTest
 * @Date: 2022/09/02 16:29
 */

public class CountDownLatchTest {
    public static void main(String[] args) throws InterruptedException {

        CountDownLatch countDownLatch = new CountDownLatch(2);

        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "，子线程开始执行..");
            countDownLatch.countDown();
            System.out.println(Thread.currentThread().getName() + "，子线程结束执行..");
        }).start();

        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "，子线程开始执行..");
            countDownLatch.countDown();
            System.out.println(Thread.currentThread().getName() + "，子线程结束执行..");
        }).start();

        countDownLatch.await();
        System.out.println("两个子线程执行完毕");
        System.out.println("主线程继续执行");
    }
}
